/**
 * @file src/main.cpp
 *
 * @section DESCRIPTION
 * This file contains the main() function.
 * The program implements the Zuker's minimum free energy model with
 * Motifs/K-turns functionality for RNA secondary structure prediction.
 *
 * @date 28-aug-2013
 *
 * @author Youri Hoogstrate
 * @author Lisa Yu
 *
 * @section LICENSE
 * yh-kt-fold can predict RNA 2D structures including K-turns.
 * Copyright (C) 2012-2013 Youri Hoogstrate
 *
 * This file is part of yh-kt-fold.
 *
 * yh-kt-fold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * yh-kt-fold is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */



#include "main.h"
#include "Settings.h"
#include "TracebackMotif.h"
#include "DotBracket.h"
#include "KTurnMotif.h"
#include "ReadData.h"
#include "Zuker.h"

#include "ScoringMatrix.h"



/**
 * @brief Predicts the structure of an RNA sequence in major 3 steps: 1) obtain parameters from IO, 2) Run the Zuker algorithm, 3) print the 2D structure.
 *
 * @param argc Number of commandline arguments.
 * @param argvs Array of strings with the actual commandline arguments.
 *
 * @date 31-mar-2013
 *
 * @return 0 For success; 1 for abnormal termination
*/
int main(int argc, char *argvs[])
{
	char s[MAXLEN];
	
	Settings *settings;
	settings = new Settings(argc, argvs);
	settings->copy_sequence(s);
	
	//bool motif = settings->get_enableMotifFunctionality();
	//printf("motif: %s \n",(motif)?"true":"false");
	
	Zuker *zuker;
	zuker = new Zuker;
	zuker->setSequence(s);
	zuker->setHairpinlen(settings->get_minHairpinlen());
	
	zuker->GibbsFreeEnergy();											//Zuker algorithm: filling phase
	
	if(settings->get_useClassicalTraceback())
	{
		zuker->tracebackOriginal();										// Zuker algorithm: traceback by Lisa Yu (deprecated)
	}
	else
	{
		zuker->traceback();												// Zuker algorithm: Novel traceback
	}
	
	/**
	 * @exception for development purpose only
	 * zuker->printWij();
	 * zuker->printVij();
	 * zuker->printPathMatrix();
	 * zuker->printTypeMatrix();
	 */
	
	zuker->print2DStructure();
	
	delete zuker;
	delete settings;
	
	/*
	Motif *m_1;
	Motif *m_2;
	Motif *m_3;
	Motif *m_4;
	m_1 = new Motif("seq5p","seq3z","name A",{16,2,77,29},{16,2,77,29},-5.3);
	m_2 = new Motif("seq5p","seq3y","name B",{16,2,77,29},{16,2,77,29},-5.3);;
	m_3 = new Motif("seq5p","seq3x","name C",{16,2,77,29},{16,2,77,29},-5.3);;
	//m_4 = new Motif("seq5p","seq3z","name D",{16,2,77,29},{16,2,77,29},-5.3);
	
	MotifTree* m;
	m = new MotifTree();
	
	printf("1\n");
	m->add_motif(m_1);
	printf("2\n");
	m->add_motif(m_2);
	printf("3\n");
	m->add_motif(m_3);
	//printf("4\n");
	//m->add_motif(m_4);
	//printf("x\n");
	std::string s1 = "seq5p";
	std::string s2 = "seq3z";
	
	m_4 = m->search_motif(s1,s2);
	if(m_4 == NULL)
	{
		printf("Untracable\n");
	}
	else
	{
		printf("FOUND!: %s\n",m_4->name.c_str());
	}
	
	delete m;
	*/
	
	//ScoringMatrix *s2;
	//s2 = new ScoringMatrix(4);
	
	return 0;
}
